home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F24358_LTSampleDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  35.4 KB  |  1,455 lines

  1. // LTSampleDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "LTSample.h"
  6. #include "VpWnd.h"
  7. #include "LTSampleDlg.h"
  8. #include "DlgProxy.h"
  9. #include "PropDialog.h"
  10. #include "SelOptPage.h"
  11. #include "QueryDialog.h"
  12. #include "AddSymbolDlg.h"
  13. #include "SmartObjectInserDlg.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. const CLSID CLSID_Application  = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  22. const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  23.  
  24. const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  25. const IID IID_Graphics = {0x6A48110A,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  26. const IID IID_IDrawing = {0x6A481107,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CAboutDlg dialog used for App About
  30.  
  31. class CAboutDlg : public CDialog
  32. {
  33. public:
  34.     CAboutDlg();
  35.  
  36. // Dialog Data
  37.     //{{AFX_DATA(CAboutDlg)
  38.     enum { IDD = IDD_ABOUTBOX };
  39.     //}}AFX_DATA
  40.  
  41.     // ClassWizard generated virtual function overrides
  42.     //{{AFX_VIRTUAL(CAboutDlg)
  43.     //}}AFX_VIRTUAL
  44.  
  45. // Implementation
  46. protected:
  47.     //{{AFX_MSG(CAboutDlg)
  48.     //}}AFX_MSG
  49.     DECLARE_MESSAGE_MAP()
  50. };
  51.  
  52. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  53. {
  54.     //{{AFX_DATA_INIT(CAboutDlg)
  55.     //}}AFX_DATA_INIT
  56. }
  57.  
  58.  
  59. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  60.     //{{AFX_MSG_MAP(CAboutDlg)
  61.         // No message handlers
  62.     //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CLTSampleDlg dialog
  67.  
  68. IMPLEMENT_DYNAMIC(CLTSampleDlg, CDialog);
  69.  
  70. CLTSampleDlg::CLTSampleDlg(CWnd* pParent /*=NULL*/)
  71.     : CDialog(CLTSampleDlg::IDD, pParent)
  72. {
  73.     //{{AFX_DATA_INIT(CLTSampleDlg)
  74.         // NOTE: the ClassWizard will add member initialization here
  75.     //}}AFX_DATA_INIT
  76.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  77.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  78.     m_pAutoProxy = NULL;
  79.  
  80.     m_pLocalApp = NULL;
  81.     m_pInprocApp = NULL;
  82.     m_pApp = NULL;
  83.     m_iVersion = 0;
  84. }
  85.  
  86. CLTSampleDlg::~CLTSampleDlg()
  87. {
  88.     // If there is an automation proxy for this dialog, set
  89.     //  its back pointer to this dialog to NULL, so it knows
  90.     //  the dialog has been deleted.
  91.     if (m_pAutoProxy != NULL)
  92.         m_pAutoProxy->m_pDialog = NULL;
  93. }
  94.  
  95. BEGIN_MESSAGE_MAP(CLTSampleDlg, CDialog)
  96.     //{{AFX_MSG_MAP(CLTSampleDlg)
  97.     ON_WM_SYSCOMMAND()
  98.     ON_WM_PAINT()
  99.     ON_WM_QUERYDRAGICON()
  100.     ON_WM_CLOSE()
  101.     ON_BN_CLICKED(IDC_MERGEDRAWING, OnMergedrawing)
  102.     ON_BN_CLICKED(IDC_OPENDRAWING, OnOpendrawing)
  103.     ON_BN_CLICKED(IDC_PASTE, OnPaste)
  104.     ON_BN_CLICKED(IDC_PROPERTYSYMBOL, OnPropertysymbol)
  105.     ON_BN_CLICKED(IDC_SAVEDRAWING, OnSavedrawing)
  106.     ON_BN_CLICKED(IDC_SELECTSYMBOL, OnSelectsymbol)
  107.     ON_BN_CLICKED(IDC_CREATEAPP, OnCreateapp)
  108.     ON_BN_CLICKED(IDC_SETVIEW, OnSetview)
  109.     ON_BN_CLICKED(IDC_NEWDRAWING, OnNewdrawing)
  110.     ON_BN_CLICKED(IDC_LOCALMODE, OnLocalmode)
  111.     ON_BN_CLICKED(IDC_INPROCMODE, OnInprocmode)
  112.     ON_BN_CLICKED(IDC_DRAWINGPROPERTY, OnDrawingProperty)
  113.     ON_BN_CLICKED(IDC_CLOSEDRAWING, OnClosedrawing)
  114.     ON_BN_CLICKED(IDC_EXPLODESYMBOL, OnExplodesymbol)
  115.     ON_BN_CLICKED(IDC_QUERY, OnQuery)
  116.     ON_BN_CLICKED(IDC_COPYSYMBOL, OnCopysymbol)
  117.     ON_BN_CLICKED(IDC_ADDSYMBOL, OnAddsymbol)
  118.     ON_BN_CLICKED(IDC_REMOVESYMBOL, OnDeletesymbol)
  119.     ON_BN_CLICKED(IDC_APPPROPERTY, OnAppproperty)
  120.     ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
  121.     ON_BN_CLICKED(IDC_GETBLOCK, OnGetblock)
  122.     //}}AFX_MSG_MAP
  123. END_MESSAGE_MAP()
  124.  
  125. void CLTSampleDlg::SyncToApplication(IApplication *pApp, BOOL bGetSelection)
  126. {
  127.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  128.     if (pDwgList != NULL)        
  129.     {
  130.         int iCount = pDwgList->GetCount();
  131.         IDrawing *pIDwg = NULL;
  132.         for (int iItem = 0; iItem < iCount; iItem++)
  133.         {
  134.             pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  135.             if (pIDwg != NULL)
  136.                 pIDwg->Release();
  137.         }
  138.         pDwgList->ResetContent();
  139.     }
  140.  
  141.     if (pApp != NULL)
  142.     {
  143.         BSTR bstrVersion = NULL;
  144.         HRESULT hRes = pApp->get_Version(0, &bstrVersion);
  145.         if (SUCCEEDED(hRes)
  146.             && bstrVersion != NULL)
  147.         {
  148.             CString cstrBuild(bstrVersion);
  149.             int iDot = cstrBuild.Find('.');
  150.             CString cstrVersion = cstrBuild.Left(iDot);
  151.             m_iVersion = atoi(cstrVersion);
  152.         }
  153.         else
  154.             m_iVersion = 4;
  155.  
  156.         // uncorrect reference counting of the Selection object
  157.         // in SDK v 4.x - I have to correct it in the my sample
  158.         if (bGetSelection
  159.             && m_iVersion > 4)
  160.             bGetSelection = FALSE;
  161.         
  162.         // Get the handle to the drawings collection
  163.         Drawings* pDwgs = NULL;
  164.         hRes = pApp->get_Drawings(&pDwgs);
  165.         if (SUCCEEDED(hRes))
  166.         {
  167.             COleVariant varIndex;
  168.             varIndex.vt = VT_I4;
  169.  
  170.             Selection *pSelection = NULL;
  171.  
  172.             for (varIndex.lVal = 0L; ; ++varIndex.lVal)
  173.             {
  174.                 IDrawing* pIDwg = NULL;
  175.                 hRes = pDwgs->get_Item(&varIndex, &pIDwg);
  176.                 if (FAILED(hRes))
  177.                     break;
  178.                 AddDrawingToList(pDwgList, pIDwg);
  179.                 
  180.                 if (bGetSelection)
  181.                 {
  182.                     // correct reference count for the Selection object
  183.                     pIDwg->get_Selection(&pSelection);
  184.                     if (pSelection != NULL)
  185.                     {
  186.                         pSelection->AddRef();
  187.                         pSelection = NULL;
  188.                     }
  189.                 }
  190.  
  191.                 pIDwg->Release();
  192.             }
  193.             pDwgs->Release();
  194.         }
  195.     }
  196.     else
  197.         m_iVersion = 0;
  198.     CButton *pCreateAppBt = (CButton *)GetDlgItem(IDC_CREATEAPP);
  199.     if (pCreateAppBt != NULL)
  200.         pCreateAppBt->EnableWindow(pApp == NULL);
  201. }
  202.  
  203. void CLTSampleDlg::AddDrawingToList(CComboBox *pDwgList, IDrawing *pIDwg)
  204. {
  205.     if (pDwgList == NULL)
  206.         return;
  207.     if (pIDwg != NULL)
  208.     {
  209.         BSTR bstrName = NULL;
  210.         HRESULT hRes = pIDwg->get_Name(&bstrName);
  211.         if (SUCCEEDED(hRes))
  212.         {
  213.             ASSERT(bstrName != NULL);
  214.             CString strName = bstrName;
  215.             ::SysFreeString(bstrName);
  216.             int iString = pDwgList->AddString(strName);
  217.             pDwgList->SetCurSel(iString);
  218.  
  219.             pDwgList->SetItemDataPtr(iString, pIDwg);
  220.             pIDwg->AddRef();
  221.         }
  222.     }
  223. }
  224. /////////////////////////////////////////////////////////////////////////////
  225. // CLTSampleDlg message handlers
  226.  
  227. BOOL CLTSampleDlg::OnInitDialog()
  228. {
  229.     CDialog::OnInitDialog();
  230.  
  231.     m_wndView.SubclassDlgItem(IDC_TCVIEW, this);
  232.  
  233.     // Add "About..." menu item to system menu.
  234.  
  235.     // IDM_ABOUTBOX must be in the system command range.
  236.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  237.     ASSERT(IDM_ABOUTBOX < 0xF000);
  238.  
  239.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  240.     if (pSysMenu != NULL)
  241.     {
  242.         CString strAboutMenu;
  243.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  244.         if (!strAboutMenu.IsEmpty())
  245.         {
  246.             pSysMenu->AppendMenu(MF_SEPARATOR);
  247.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  248.         }
  249.     }
  250.  
  251.     // Set the icon for this dialog.  The framework does this automatically
  252.     //  when the application's main window is not a dialog
  253.     SetIcon(m_hIcon, TRUE);            // Set big icon
  254.     SetIcon(m_hIcon, FALSE);        // Set small icon
  255.     
  256.     CButton *pButton = (CButton *)GetDlgItem(IDC_LOCALMODE);
  257.     if (pButton != NULL
  258.         && ::IsWindow(pButton->GetSafeHwnd()))
  259.         pButton->SetCheck(1);
  260.  
  261.     
  262.     return TRUE;  // return TRUE  unless you set the focus to a control
  263. }
  264.  
  265. void CLTSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  266. {
  267.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  268.     {
  269.         CAboutDlg dlgAbout;
  270.         dlgAbout.DoModal();
  271.     }
  272.     else
  273.     {
  274.         CDialog::OnSysCommand(nID, lParam);
  275.     }
  276. }
  277.  
  278. // If you add a minimize button to your dialog, you will need the code below
  279. //  to draw the icon.  For MFC applications using the document/view model,
  280. //  this is automatically done for you by the framework.
  281.  
  282. void CLTSampleDlg::OnPaint() 
  283. {
  284.     if (IsIconic())
  285.     {
  286.         CPaintDC dc(this); // device context for painting
  287.  
  288.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  289.  
  290.         // Center icon in client rectangle
  291.         int cxIcon = GetSystemMetrics(SM_CXICON);
  292.         int cyIcon = GetSystemMetrics(SM_CYICON);
  293.         CRect rect;
  294.         GetClientRect(&rect);
  295.         int x = (rect.Width() - cxIcon + 1) / 2;
  296.         int y = (rect.Height() - cyIcon + 1) / 2;
  297.  
  298.         // Draw the icon
  299.         dc.DrawIcon(x, y, m_hIcon);
  300.     }
  301.     else
  302.     {
  303.         CDialog::OnPaint();
  304.     }
  305. }
  306.  
  307. // The system calls this to obtain the cursor to display while the user drags
  308. //  the minimized window.
  309. HCURSOR CLTSampleDlg::OnQueryDragIcon()
  310. {
  311.     return (HCURSOR) m_hIcon;
  312. }
  313.  
  314. // Automation servers should not exit when a user closes the UI
  315. //  if a controller still holds on to one of its objects.  These
  316. //  message handlers make sure that if the proxy is still in use,
  317. //  then the UI is hidden but the dialog remains around if it
  318. //  is dismissed.
  319.  
  320. void CLTSampleDlg::OnClose() 
  321. {
  322.     if (CanExit())
  323.     {
  324.         CDialog::OnClose();
  325.  
  326.         m_wndView.SetView(NULL);
  327.  
  328.         CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  329.         if (pDwgList != NULL)        
  330.         {
  331.             int iCount = pDwgList->GetCount();
  332.             for (int iItem = 0; iItem < iCount; iItem++)
  333.             {
  334.                 IDrawing *pIDwg = NULL;
  335.                 pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  336.                 if (pIDwg != NULL)
  337.                     pIDwg->Release();
  338.             }
  339.         }
  340.         if (m_pLocalApp != NULL)
  341.             m_pLocalApp->Release();
  342.         if (m_pInprocApp != NULL)
  343.             m_pInprocApp->Release();
  344.     }
  345. }
  346.  
  347. void CLTSampleDlg::OnOK() 
  348. {
  349.     if (CanExit())
  350.         CDialog::OnOK();
  351. }
  352.  
  353. void CLTSampleDlg::OnCancel() 
  354. {
  355.     if (CanExit())
  356.         CDialog::OnCancel();
  357. }
  358.  
  359. BOOL CLTSampleDlg::CanExit()
  360. {
  361.     // If the proxy object is still around, then the automation
  362.     //  controller is still holding on to this application.  Leave
  363.     //  the dialog around, but hide its UI.
  364.     if (m_pAutoProxy != NULL)
  365.     {
  366.         ShowWindow(SW_HIDE);
  367.         return FALSE;
  368.     }
  369.  
  370.     return TRUE;
  371. }
  372.  
  373. static char BASED_CODE szFilter[] = "TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||";
  374.  
  375. void CLTSampleDlg::OnMergedrawing() 
  376. {
  377.     if (m_pApp == NULL)
  378.     {
  379.         AfxMessageBox(IDS_CREATEAPPFIRST);
  380.         return;
  381.     }
  382.  
  383.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  384.  
  385.         // Pointer to Drawings collection
  386.     Drawings* pDwgs = NULL;
  387.  
  388.     // Pointer to drawing intrface
  389.     IDrawing* pIDwgOpen = NULL;
  390.  
  391.     Properties *pProps = NULL;
  392.     Property *pProp = NULL;
  393.     Graphics *pGrs = NULL;
  394.  
  395.     Properties *pPropsOpen = NULL;
  396.     Property *pPropOpen = NULL;
  397.     Graphics *pGrsOpen = NULL;
  398.  
  399.     IGraphic *pIGr = NULL;
  400.     BSTR bstrPath = NULL;
  401. //    BSTR bstrMode = NULL;
  402.  
  403.             // Make a "missing" optional parameter
  404.     VARIANT varMissing;
  405.     varMissing.vt = VT_ERROR;
  406.     varMissing.scode = DISP_E_PARAMNOTFOUND;
  407.  
  408.     int iSelItem = pDwgList->GetCurSel();
  409.     if (iSelItem >= 0)
  410.     {
  411.         CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  412.         if (dlg.DoModal() != IDOK)
  413.             return;
  414.  
  415.         // Get the handle to the drawings collection
  416.         TRY
  417.         {
  418.  
  419.             IDrawing *pIDwg = NULL;
  420.             HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  421.             CHECK_HRESULT(hRes)
  422.  
  423.             // Get the file name into a BSTR
  424.             CString strPath = dlg.GetPathName();
  425.             bstrPath = strPath.AllocSysString();
  426.  
  427.             // Add the drawing to the drawings collection
  428.             hRes = pDwgs->Open(bstrPath, &varMissing, &varMissing, &pIDwgOpen);
  429.             CHECK_HRESULT(hRes)
  430.  
  431.             pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  432.             if (pIDwg != NULL)
  433.             {                
  434. //                CString cstrMode("TileMode");
  435. //                bstrMode = cstrMode.AllocSysString();
  436.  
  437.                 COleVariant varPropName("TileMode");
  438.                 COleVariant varMode;
  439.                 COleVariant varOldMode;
  440.  
  441.                 hRes = pIDwgOpen->get_Properties(&pPropsOpen);
  442.                 CHECK_HRESULT(hRes)
  443.  
  444.                 hRes = pPropsOpen->get_Item(&varPropName, &pPropOpen);
  445.                 CHECK_HRESULT(hRes)
  446.  
  447.                 hRes = pIDwg->get_Properties(&pProps);
  448.                 CHECK_HRESULT(hRes)
  449.  
  450.                 hRes = pProps->get_Item(&varPropName, &pProp);
  451.                 CHECK_HRESULT(hRes)
  452.  
  453.                 hRes = pProp->get_Value(0, &varMode);
  454.                 CHECK_HRESULT(hRes)
  455.  
  456.                 varOldMode = varMode;
  457.  
  458.                 hRes = pPropOpen->put_Value(0, &varMode);
  459.                 CHECK_HRESULT(hRes)
  460.  
  461.                 hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
  462.                 CHECK_HRESULT(hRes)
  463.  
  464.                 long lCount = 0;
  465.                 hRes = pGrsOpen->get_Count(&lCount);
  466.                 CHECK_HRESULT(hRes)
  467.  
  468.                 hRes = pIDwg->get_Graphics(&pGrs);
  469.                 CHECK_HRESULT(hRes)
  470.  
  471.                 COleVariant varIndex((const long&)0);
  472.  
  473.                 for (long lItem = 0; lItem < lCount; lItem++)
  474.                 {
  475.                     hRes = pGrsOpen->Remove(&varIndex, &pIGr);
  476.                     CHECK_HRESULT(hRes)
  477.  
  478.                     hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
  479.                     CHECK_HRESULT(hRes)
  480.                     pIGr->Release();
  481.                     pIGr = NULL;
  482.                 }
  483.  
  484.                 pGrsOpen->Release();
  485.                 pGrsOpen = NULL;
  486.  
  487.                 pGrs->Release();
  488.                 pGrs = NULL;
  489.  
  490.                 // merge next space
  491.                 if (varMode.iVal == 0)
  492.                     varMode.iVal = 1;
  493.                 else
  494.                     varMode.iVal = 0;
  495.  
  496.                 hRes = pProp->put_Value(0, &varMode);
  497.                 CHECK_HRESULT(hRes)
  498.  
  499.                 hRes = pPropOpen->put_Value(0, &varMode);
  500.                 CHECK_HRESULT(hRes)
  501.  
  502.                 hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
  503.                 CHECK_HRESULT(hRes)
  504.  
  505.                 hRes = pGrsOpen->get_Count(&lCount);
  506.                 CHECK_HRESULT(hRes)
  507.  
  508.                 hRes = pIDwg->get_Graphics(&pGrs);
  509.                 CHECK_HRESULT(hRes)
  510.  
  511.                 for (lItem = 0; lItem < lCount; lItem++)
  512.                 {
  513.                     hRes = pGrsOpen->Remove(&varIndex,&pIGr);
  514.                     CHECK_HRESULT(hRes)
  515.  
  516.                     hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
  517.                     CHECK_HRESULT(hRes)
  518.                     pIGr->Release();
  519.                     pIGr = NULL;
  520.                 }
  521.  
  522.             }
  523.         }
  524.         CATCH_ALL(e)
  525.         {
  526.         }
  527.         END_CATCH_ALL
  528.     }
  529.     else
  530.         OnOpendrawing();
  531.  
  532.     if (bstrPath != NULL)
  533.         ::SysFreeString(bstrPath);
  534. //    if (bstrMode)
  535. //        ::SysFreeString(bstrMode);
  536.  
  537.     if (pIGr != NULL)
  538.         pIGr->Release();
  539.  
  540.     if (pGrsOpen != NULL)
  541.         pGrsOpen->Release();
  542.  
  543.     if (pPropOpen != NULL)
  544.         pPropOpen->Release();
  545.  
  546.     if (pPropsOpen != NULL)
  547.         pPropsOpen->Release();
  548.  
  549.     if (pGrs != NULL)
  550.         pGrs->Release();
  551.  
  552.     if (pProp != NULL)
  553.         pProp->Release();
  554.  
  555.     if (pProps != NULL)
  556.         pProps->Release();
  557.  
  558.     if (pIDwgOpen != NULL)
  559.     {
  560.         pIDwgOpen->Close(&varMissing, &varMissing, &varMissing);
  561.         pIDwgOpen->Release();
  562.     }
  563.  
  564.     if (pDwgs != NULL)
  565.         pDwgs->Release();;
  566.  
  567. }
  568.  
  569. void CLTSampleDlg::OnOpendrawing() 
  570. {
  571.     if (m_pApp == NULL)
  572.     {
  573.         AfxMessageBox(IDS_CREATEAPPFIRST);
  574.         return;
  575.     }
  576.     CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  577.     if (dlg.DoModal() != IDOK)
  578.         return;
  579.  
  580.     // Pointer to Drawings collection
  581.     Drawings* pDwgs = NULL;
  582.  
  583.     // Get the handle to the drawings collection
  584.     HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  585.     if (FAILED(hRes))
  586.     {
  587.         return;
  588.     }
  589.     
  590.     // Pointer to drawing object
  591.     IDrawing* pIDwg = NULL;
  592.  
  593.     // Make a "missing" optional parameter
  594.     VARIANT var;
  595.     var.vt = VT_ERROR;
  596.     var.scode = DISP_E_PARAMNOTFOUND;
  597.  
  598.     // Get the file name into a BSTR
  599.     CString strPath = dlg.GetPathName();
  600.     BSTR bstrPath = strPath.AllocSysString();
  601.  
  602.     // Add the drawing to the drawings collection
  603.     hRes = pDwgs->Open(bstrPath, &var, &var, &pIDwg);
  604.  
  605.     // Free the system memory for the BSTR
  606.     ::SysFreeString(bstrPath);
  607.  
  608.     if (SUCCEEDED(hRes))
  609.     {
  610.         CComboBox* pDwgsList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  611.         AddDrawingToList(pDwgsList, pIDwg);
  612.         pIDwg->Release();
  613.     }
  614.     else
  615.     {
  616.         // File was not opened.  Maybe the filter gave us a reason.
  617.         CString strDesc("Unknown");
  618.  
  619.         // Try to get thread-wide error object
  620.         IErrorInfo* pErrorInfo = NULL;
  621.         if (SUCCEEDED(::GetErrorInfo(0, &pErrorInfo)))
  622.         {
  623.             // Try to get description string
  624.             BSTR bstrDesc = NULL;
  625.             if (SUCCEEDED(pErrorInfo->GetDescription(&bstrDesc)))
  626.             {
  627.                 strDesc = bstrDesc;
  628.                 ::SysFreeString(bstrDesc);
  629.             }
  630.             pErrorInfo->Release();
  631.         }
  632.  
  633.         // Display failure message
  634.         CString msg = "Could not open '" + strPath + "': " + strDesc;
  635.         MessageBox(msg);
  636.     }
  637.  
  638.     // Finished with drawings collection, decrement reference count
  639.     pDwgs->Release();
  640.     
  641. }
  642.  
  643. void CLTSampleDlg::OnPaste() 
  644. {
  645.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  646.     if (pDwgList != NULL)
  647.     {
  648.         int iSelItem = pDwgList->GetCurSel();
  649.         if (iSelItem >= 0)
  650.         {
  651.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  652.             if (pIDwg != NULL)
  653.             {
  654.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PASTE);
  655.                 pPropBt->EnableWindow(FALSE);
  656.  
  657.                 HRESULT hRes = pIDwg->Paste();
  658.                 if (FAILED(hRes))
  659.                     AfxMessageBox(IDS_PASTEFAILED);
  660.                 pPropBt->EnableWindow(TRUE);
  661.             }
  662.             else
  663.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  664.         }
  665.     }
  666. }
  667.  
  668. void CLTSampleDlg::OnPropertysymbol() 
  669. {
  670.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  671.     if (pDwgList != NULL)
  672.     {
  673.         int iSelItem = pDwgList->GetCurSel();
  674.         if (iSelItem >= 0)
  675.         {
  676.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  677.             if (pIDwg != NULL)
  678.             {
  679.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  680.                 pPropBt->EnableWindow(FALSE);
  681.                 Selection *pSelection = NULL;
  682.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  683.                 if (SUCCEEDED(hRes))
  684.                 {
  685.                     long lCount;
  686.                     hRes = pSelection->get_Count(&lCount);
  687.                     if (SUCCEEDED(hRes))
  688.                     {
  689.                         if (lCount = 1)
  690.                         {
  691.                             IGraphic *pIGr = NULL;
  692.                             COleVariant varIndex((const long&)0);
  693.  
  694.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  695.                             if (SUCCEEDED(hRes))
  696.                             {
  697.                                 Properties *pProps = NULL;
  698.                                 hRes = pIGr->get_Properties(&pProps);
  699.                                 if (SUCCEEDED(hRes))
  700.                                 {
  701.                                     CPropDialog dlgProp(pProps, this);
  702.                                     if (dlgProp.DoModal() == IDOK)
  703.                                     {
  704.                                     }
  705.                                     pProps->Release();
  706.                                 }
  707.                                 else
  708.                                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  709.                                 pIGr->Release();
  710.                             }
  711.                             else
  712.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  713.                         }
  714.                         else
  715.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  716.                     }
  717.                     else
  718.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  719.                     pSelection->Release();
  720.                 }
  721.                 else
  722.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  723.                 pPropBt->EnableWindow(TRUE);
  724.             }
  725.             else
  726.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  727.         }
  728.     }
  729. }
  730.  
  731. void CLTSampleDlg::OnSavedrawing() 
  732. {
  733.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  734.     HRESULT hRes = S_OK;
  735.     if (pDwgList != NULL)        
  736.     {
  737.         CButton *pSaveBt = (CButton *)GetDlgItem(IDC_SAVEDRAWING);
  738.         pSaveBt->EnableWindow(FALSE);
  739.  
  740.         int iItem = pDwgList->GetCurSel();
  741.         if (iItem >= 0)
  742.         {
  743.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  744.             if (pIDwg != NULL)
  745.             {
  746.                 CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  747.                 if (dlg.DoModal() == IDOK)
  748.                 {
  749.                     // Make a "missing" optional parameter
  750.                     VARIANT var;
  751.                     var.vt = VT_ERROR;
  752.                     var.scode = DISP_E_PARAMNOTFOUND;
  753.  
  754.                     // Get the file name into a BSTR
  755.                     CString strPath = dlg.GetPathName();
  756.                     BSTR bstrPath = strPath.AllocSysString();
  757.  
  758.                     HRESULT hRes = pIDwg->SaveAs(bstrPath, &var);
  759.  
  760.                     // Free the system memory for the BSTR
  761.                     ::SysFreeString(bstrPath);
  762.                 }
  763.             }
  764.         }
  765.         else
  766.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  767.         pSaveBt->EnableWindow(TRUE);
  768.     }
  769. }
  770.  
  771. void CLTSampleDlg::OnSelectsymbol() 
  772. {
  773.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  774.     HRESULT hRes = S_OK;
  775.     if (pDwgList != NULL)        
  776.     {
  777.         CButton *pSelectBt = (CButton *)GetDlgItem(IDC_SELECTSYMBOL);
  778.         if (pSelectBt->IsWindowEnabled())
  779.         {
  780.             int iItem = pDwgList->GetCurSel();
  781.             if (iItem >= 0)
  782.             {
  783.                 IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  784.                 if (pIDwg != NULL)
  785.                 {
  786.                     Selection *pSel = NULL;
  787.                     hRes = pIDwg->get_Selection(&pSel);
  788.                     if (SUCCEEDED(hRes))
  789.                     {
  790.                         pSel->Unselect();
  791.                         pSel->Release();
  792.                     }
  793.                 }
  794.                 m_wndView.SetSelectMode();
  795.                 pSelectBt->EnableWindow(FALSE);
  796.             }
  797.             else
  798.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  799.         }
  800.         else
  801.         {
  802.             pSelectBt->EnableWindow(TRUE);
  803.             m_wndView.SetSelectMode();
  804.         }
  805.     }
  806. }
  807.  
  808. void CLTSampleDlg::OnCreateapp() 
  809. {
  810.     CButton *pBtCreate = (CButton *)GetDlgItem(IDC_CREATEAPP);
  811.     if (pBtCreate != NULL
  812.         && ::IsWindow(pBtCreate->GetSafeHwnd()))
  813.         pBtCreate->EnableWindow(FALSE);
  814.  
  815.     int iLocal = 0;
  816.     CButton *pBtLocal = (CButton *)GetDlgItem(IDC_LOCALMODE);
  817.     if (pBtLocal != NULL
  818.         && ::IsWindow(pBtLocal->GetSafeHwnd()))
  819.         iLocal = pBtLocal->GetCheck();
  820.  
  821.     int iInproc = 0;
  822.     CButton *pBtInproc = (CButton *)GetDlgItem(IDC_INPROCMODE);
  823.     if (pBtInproc != NULL
  824.         && ::IsWindow(pBtInproc->GetSafeHwnd()))
  825.         iInproc = pBtInproc->GetCheck();
  826.  
  827.     HRESULT hRes = S_OK;
  828.     if (iLocal == 1)
  829.     {
  830.         ASSERT(iInproc != 1);
  831.         if (m_pLocalApp == NULL)
  832.         {
  833.             IUnknown* pIUnk = NULL;
  834.             hRes = ::GetActiveObject(CLSID_Application, NULL, &pIUnk);
  835.             if (FAILED(hRes))
  836.             {
  837.                 hRes = CoCreateInstance(CLSID_Application,    //Class identifier (CLSID) of the object
  838.                                         NULL,    //Object is or isn't part of an aggregate 
  839.                                         CLSCTX_LOCAL_SERVER,    //Context for running executable code
  840.                                         IID_IUnknown,    //Interface identifier
  841.                                         (void**)&pIUnk    //Points to requested interface pointer
  842.                 );    
  843.  
  844.                 if (FAILED(hRes))
  845.                 {
  846.                     AfxMessageBox(IDS_COULDNOTCREATELOCALSERVER);
  847.                     return;
  848.                 }
  849.             }
  850.  
  851.             hRes = pIUnk->QueryInterface(IID_IApplication, (void**)&m_pLocalApp);
  852.             pIUnk->Release();
  853.             if (FAILED(hRes))
  854.             {
  855.                 AfxMessageBox(IDS_OBJECTISNOTTURBOCADAPPLICATION);
  856.             }
  857.         }
  858.         else
  859.             AfxMessageBox(IDS_LOCALSERVERALREADYRUNNING);
  860.         m_pApp = m_pLocalApp;
  861.     }
  862.     else if (iInproc == 1)
  863.     {
  864.         if (m_pInprocApp == NULL)
  865.         {
  866.             hRes = CoCreateInstance(CLSID_XApplication,    //Class identifier (CLSID) of the object
  867.                                     NULL,    //Object is or isn't part of an aggregate
  868.                                     CLSCTX_INPROC_SERVER,    //Context for running executable code
  869.                                     IID_IApplication,    //Interface identifier
  870.                                     (void**)&m_pInprocApp    //Points to requested interface pointer
  871.             );
  872.  
  873.             if (FAILED(hRes))
  874.                 AfxMessageBox(IDS_COULDNOTCREATEINPROCSERVER);
  875.     
  876.         }
  877.         else
  878.             AfxMessageBox(IDS_INPROCSERVERALREADYCREATED);
  879.         m_pApp = m_pInprocApp;
  880.     }
  881.     else
  882.         ASSERT(FALSE);
  883.  
  884.     // uncorrect reference counting of the Selection object
  885.     // in SDK v 4.x - I have to correct it in the my sample
  886.     // when create Application object
  887.     SyncToApplication(m_pApp, TRUE);
  888.     if (m_pApp != NULL)
  889.         AfxMessageBox(IDS_APPCOMPLETE);
  890. }
  891.  
  892.  
  893. void CLTSampleDlg::OnSetview() 
  894. {
  895.     
  896.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  897.     if (pDwgList != NULL)        
  898.     {
  899.         int iItem = pDwgList->GetCurSel();
  900.         if (iItem >= 0)
  901.         {
  902.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  903.             Views *pViews = NULL;
  904.             HRESULT hRes = pIDwg->get_Views(&pViews);
  905.             if (SUCCEEDED(hRes))
  906.             {
  907.                 // Pointer to view object
  908.                 View* pView = NULL;
  909.  
  910.                 // Make a "missing" optional parameter
  911.                 VARIANT var;
  912.                 var.vt = VT_ERROR;
  913.                 var.scode = DISP_E_PARAMNOTFOUND;
  914.  
  915.                 // Add the view to the collection
  916.                 hRes = pViews->Add(&var, &var, &pView);
  917.  
  918.                 if (SUCCEEDED(hRes))
  919.                 {
  920.                     // Set up view to be the active view
  921.                     m_wndView.SetView(pView);
  922.  
  923.                     // Finished with view, decrement reference count
  924.                     pView->Release();
  925.                 }
  926.  
  927.                 // Finished with views, decrement reference count
  928.                 pViews->Release();
  929.             }
  930.         }
  931.         else
  932.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  933.     }
  934. }
  935.  
  936. void CLTSampleDlg::OnNewdrawing() 
  937. {
  938.     if (m_pApp == NULL)
  939.     {
  940.         AfxMessageBox(IDS_CREATEAPPFIRST);
  941.         return;
  942.     }
  943.  
  944.     Drawings* pDwgs = NULL;
  945.  
  946.     // Get the handle to the drawings collection
  947.     HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  948.     if (FAILED(hRes))
  949.     {
  950.         return;
  951.     }
  952.     
  953.     // Pointer to drawing object
  954.     IDrawing* pIDwg = NULL;
  955.  
  956.     // Make a "missing" optional parameter
  957.     VARIANT var;
  958.     var.vt = VT_ERROR;
  959.     var.scode = DISP_E_PARAMNOTFOUND;
  960.  
  961.     // Add the drawing to the drawings collection
  962.     hRes = pDwgs->Add(&var, &pIDwg);
  963.     if (SUCCEEDED(hRes))
  964.     {
  965.         CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  966.         AddDrawingToList(pDwgList, pIDwg);
  967.         pIDwg->Release();
  968.     }
  969.  
  970.     // Finished with drawings collection, decrement reference count
  971.     pDwgs->Release();
  972. }
  973.  
  974. void CLTSampleDlg::OnLocalmode() 
  975. {
  976.     m_pApp = m_pLocalApp;
  977.     SyncToApplication(m_pApp);
  978. }
  979.  
  980. void CLTSampleDlg::OnInprocmode() 
  981. {
  982.     m_pApp = m_pInprocApp;
  983.     SyncToApplication(m_pApp);
  984. }
  985.  
  986. void CLTSampleDlg::OnDrawingProperty() 
  987. {
  988.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  989.     if (pDwgList != NULL)
  990.     {
  991.         int iSelItem = pDwgList->GetCurSel();
  992.         if (iSelItem >= 0)
  993.         {
  994.             CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
  995.             pPropBt->EnableWindow(FALSE);
  996.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  997.             if (pIDwg != NULL)
  998.             {
  999.                 Properties *pProps = NULL;
  1000.                 HRESULT hRes = pIDwg->get_Properties(&pProps);
  1001.                 if (SUCCEEDED(hRes))
  1002.                 {
  1003.                     CPropDialog dlgProp(pProps, this);
  1004.                     if (dlgProp.DoModal() == IDOK)
  1005.                     {
  1006.                     }
  1007.                     pProps->Release();
  1008.                 }
  1009.                 else
  1010.                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1011.             }
  1012.             pPropBt->EnableWindow(TRUE);
  1013.         }
  1014.         else
  1015.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1016.     }
  1017. }
  1018.  
  1019. void CLTSampleDlg::OnClosedrawing() 
  1020. {
  1021.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1022.     if (pDwgList != NULL)
  1023.     {
  1024.         int iSelItem = pDwgList->GetCurSel();
  1025.         if (iSelItem >= 0)
  1026.         {
  1027.             CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
  1028.             pPropBt->EnableWindow(FALSE);
  1029.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1030.             if (pIDwg != NULL)
  1031.             {
  1032.                 IDrawing *pIDwgView = m_wndView.GetDrawing();
  1033.                 if (pIDwgView == pIDwg)
  1034.                 {
  1035.                     m_wndView.SetView(NULL);
  1036.                     m_wndView.Invalidate();
  1037.                     m_wndView.UpdateWindow();
  1038.                     pIDwgView->Release();
  1039.                 }
  1040.  
  1041.                 VARIANT var;
  1042.                 var.vt = VT_ERROR;
  1043.                 var.scode = DISP_E_PARAMNOTFOUND;
  1044.                 pIDwg->Close(&var, &var, &var);
  1045.                 pIDwg->Release();
  1046.  
  1047.                 pDwgList->DeleteString(iSelItem);
  1048.                 pDwgList->SetCurSel(iSelItem - 1);
  1049.             }
  1050.             pPropBt->EnableWindow(TRUE);
  1051.         }
  1052.         else
  1053.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1054.     }    
  1055. }
  1056.  
  1057. void CLTSampleDlg::OnExplodesymbol() 
  1058. {
  1059.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1060.     if (pDwgList != NULL)
  1061.     {
  1062.         int iSelItem = pDwgList->GetCurSel();
  1063.         if (iSelItem >= 0)
  1064.         {
  1065.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1066.             if (pIDwg != NULL)
  1067.             {
  1068.                 CButton *pExplBt = (CButton *)GetDlgItem(IDC_EXPLODESYMBOL);
  1069.                 pExplBt->EnableWindow(FALSE);
  1070.                 Selection *pSelection = NULL;
  1071.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1072.                 if (SUCCEEDED(hRes))
  1073.                 {
  1074.                     long lCount;
  1075.                     hRes = pSelection->get_Count(&lCount);
  1076.                     if (SUCCEEDED(hRes))
  1077.                     {
  1078.                         if (lCount = 1)
  1079.                         {
  1080.                             IGraphic *pIGr = NULL;
  1081.                             COleVariant varIndex((const long&)0);
  1082.  
  1083.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  1084.                             if (SUCCEEDED(hRes))
  1085.                             {
  1086.                                 GraphicSet *pSet = NULL;
  1087.                                 hRes = pIGr->Explode(&pSet);
  1088.                                 if (SUCCEEDED(hRes))
  1089.                                 {
  1090.                                     pSet->Release();
  1091.                                 }
  1092.                                 else
  1093.                                     AfxMessageBox(IDS_CANNOTEXPLODEGRAPHIC);
  1094.                                 pIGr->Release();
  1095.                             }
  1096.                             else
  1097.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1098.                         }
  1099.                         else
  1100.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1101.                     }
  1102.                     else
  1103.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1104.                     pSelection->Release();
  1105.                 }
  1106.                 else
  1107.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1108.                 pExplBt->EnableWindow(TRUE);
  1109.             }
  1110.             else
  1111.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1112.         }
  1113.     }
  1114. }
  1115.  
  1116. void CLTSampleDlg::OnQuery() 
  1117. {
  1118.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1119.     if (pDwgList != NULL)
  1120.     {
  1121.         int iSelItem = pDwgList->GetCurSel();
  1122.         if (iSelItem >= 0)
  1123.         {
  1124.             CButton *pQueryBt = (CButton *)GetDlgItem(IDC_QUERY);
  1125.             pQueryBt->EnableWindow(FALSE);
  1126.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1127.             if (pIDwg != NULL)
  1128.             {
  1129.                 Graphics *pGrs = NULL;
  1130.                 HRESULT hRes = pIDwg->get_Graphics(&pGrs);
  1131.                 if (SUCCEEDED(hRes))
  1132.                 {
  1133.                     CQueryDialog dlgQuery(this);
  1134.                     if (dlgQuery.DoModal() == IDOK)
  1135.                     {
  1136.                         GraphicSet *pGrSet = NULL;
  1137.                         BSTR bstrQuery = dlgQuery.m_cstrQueryString.AllocSysString();
  1138.                         hRes = pGrs->QuerySet(bstrQuery, &pGrSet);
  1139.                         if (SUCCEEDED(hRes))
  1140.                         {
  1141.                             if (pGrSet != NULL)
  1142.                             {
  1143.                                 hRes = pGrSet->Select();
  1144.                                 if (SUCCEEDED(hRes))
  1145.                                     AfxMessageBox(IDS_QUERYSET_SUCCEEDED);
  1146.                                 else
  1147.                                     AfxMessageBox(IDS_CANNOTSELECTGRAPHIC);
  1148.                                 pGrSet->Release();
  1149.                             }
  1150.                             m_wndView.Invalidate();
  1151.                             m_wndView.UpdateWindow();
  1152.                         }
  1153.                         else
  1154.                             AfxMessageBox(IDS_QUERYSET_FAILED);
  1155.                         ::SysFreeString(bstrQuery);
  1156.                     }
  1157.                     pGrs->Release();
  1158.                 }
  1159.                 else
  1160.                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1161.             }
  1162.             pQueryBt->EnableWindow(TRUE);
  1163.         }
  1164.         else
  1165.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1166.     }
  1167. }
  1168.  
  1169. void CLTSampleDlg::OnCopysymbol() 
  1170. {
  1171.     // TODO: Add your control notification handler code here
  1172.     
  1173. }
  1174.  
  1175. void CLTSampleDlg::OnAddsymbol() 
  1176. {
  1177.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1178.     if (pDwgList != NULL)
  1179.     {
  1180.         int iSelItem = pDwgList->GetCurSel();
  1181.         if (iSelItem >= 0)
  1182.         {
  1183.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1184.             if (pIDwg != NULL)
  1185.             {
  1186.                 CAddSymbolDlg dlgAdd(this);
  1187.                 if (dlgAdd.DoModal() == IDOK)
  1188.                 {
  1189.                     HRESULT hRes = S_OK;
  1190.                     switch (dlgAdd.m_iInsert)
  1191.                     {
  1192.                         case 0:
  1193.                         {
  1194.                             RegenMethods *pRegens = NULL;
  1195.                             hRes = m_pApp->get_RegenMethods(&pRegens);
  1196.                             if (SUCCEEDED(hRes))
  1197.                             {
  1198.                                 CSmartObjectInserDlg dlgInsert(pRegens, this);
  1199.                                 if (dlgInsert.DoModal())
  1200.                                 {
  1201.                                     VARIANT varMissing;
  1202.                                     ::VariantInit(&varMissing);
  1203.                                     varMissing.vt = VT_ERROR;
  1204.                                     varMissing.scode = DISP_E_PARAMNOTFOUND;
  1205.                                     
  1206.                                     VARIANT varType;
  1207.                                     ::VariantInit(&varType);
  1208.                                     varType.vt = VT_I4;
  1209.                                     varType.lVal = imsiPolyline;
  1210.  
  1211.                                     VARIANT varRegenType;
  1212.                                     ::VariantInit(&varRegenType);
  1213.                                     varRegenType.vt = VT_I4;
  1214.                                     varRegenType.lVal = dlgInsert.m_dwID;
  1215.  
  1216.                                     IGraphic *pIGr = NULL;
  1217.                                     Graphics *pGrs = NULL;
  1218.                                     hRes = pIDwg->get_Graphics(&pGrs);
  1219.                                     if (SUCCEEDED(hRes))
  1220.                                     {
  1221.                                         
  1222.                                         switch (dlgInsert.m_rmType)
  1223.                                         {
  1224.                                             case imsiAutomation:
  1225.                                             {
  1226.                                                 hRes = pGrs->Add(&varType,
  1227.                                                                  &varRegenType,
  1228.                                                                  &varMissing,
  1229.                                                                  &varMissing,
  1230.                                                                  &varMissing,
  1231.                                                                  &varMissing,
  1232.                                                                  &pIGr);
  1233.                                             }
  1234.                                             break;
  1235.                                             case imsiVTbl:
  1236.                                                 AfxMessageBox(IDS_NOTIMPLEMENTED);
  1237.                                             break;
  1238.                                             case imsiScript:
  1239.                                                 AfxMessageBox(IDS_NOTIMPLEMENTED);
  1240.                                             break;
  1241.                                         }
  1242.                                         if (pIGr != NULL)
  1243.                                             pIGr->Release();
  1244.                                         pGrs->Release();
  1245.                                     }
  1246.                                     else
  1247.                                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1248.                                 }
  1249.                             }
  1250.                             else
  1251.                                 AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1252.                         }
  1253.                         break;
  1254.                         case 1:
  1255.                         default:
  1256.                             AfxMessageBox(IDS_NOTIMPLEMENTED);
  1257.                         break;
  1258.                     }
  1259.                 }
  1260.             }
  1261.             else
  1262.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1263.         }
  1264.         else
  1265.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1266.     }
  1267. }
  1268.  
  1269. void CLTSampleDlg::OnDeletesymbol() 
  1270. {
  1271.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1272.     if (pDwgList != NULL)
  1273.     {
  1274.         int iSelItem = pDwgList->GetCurSel();
  1275.         if (iSelItem >= 0)
  1276.         {
  1277.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1278.             if (pIDwg != NULL)
  1279.             {
  1280.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  1281.                 pPropBt->EnableWindow(FALSE);
  1282.                 Selection *pSelection = NULL;
  1283.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1284.                 if (SUCCEEDED(hRes))
  1285.                 {
  1286.                     long lCount;
  1287.                     hRes = pSelection->get_Count(&lCount);
  1288.                     if (SUCCEEDED(hRes))
  1289.                     {
  1290.                         IGraphic *pIGr = NULL;
  1291.                         COleVariant varIndex((const long&)0);
  1292.  
  1293.                         hRes = pSelection->get_Item(varIndex, &pIGr);
  1294.                         if (SUCCEEDED(hRes))
  1295.                         {
  1296.                             long index;
  1297.                             hRes = pIGr->get_Index(&index);
  1298.                             if (SUCCEEDED(hRes))
  1299.                             {
  1300.                                 IDispatch *pIDisp = NULL;
  1301.                                 hRes = pIGr->get_Parent(&pIDisp);
  1302.                                 if (SUCCEEDED(hRes))
  1303.                                 {
  1304.                                     Graphics *pGrs = NULL;
  1305.                                     IDrawing *pIDwg = NULL;
  1306.                                     hRes = pIDisp->QueryInterface(IID_IDrawing, (void **)&pIDwg);
  1307.                                     if (SUCCEEDED(hRes))
  1308.                                         hRes = pIDwg->get_Graphics(&pGrs);
  1309.                                     else
  1310.                                         hRes = pIDisp->QueryInterface(IID_Graphics, (void **)&pGrs);
  1311.                                     pIDisp->Release();
  1312.                                     if (SUCCEEDED(hRes))
  1313.                                     {
  1314.                                         varIndex = index;
  1315.                                         IGraphic *pIGrRemoved = NULL;
  1316.                                         hRes = pGrs->Remove(&varIndex, &pIGrRemoved);
  1317.                                         if (SUCCEEDED(hRes))
  1318.                                         {
  1319.                                             AfxMessageBox(IDS_SYMBOLREMOVEDFROMDRAWING);
  1320.                                             pIGrRemoved->Release();
  1321.                                         }
  1322.                                         pGrs->Release();
  1323.                                     }
  1324.                                 }
  1325.                             }
  1326.                             pIGr->Release();
  1327.                         }
  1328.                         else
  1329.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1330.                     }
  1331.                     else
  1332.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1333.                     pSelection->Release();
  1334.                 }
  1335.                 else
  1336.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1337.                 pPropBt->EnableWindow(TRUE);
  1338.             }
  1339.         }
  1340.         else
  1341.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1342.     }
  1343. }
  1344.  
  1345. void CLTSampleDlg::OnAppproperty() 
  1346. {
  1347.     if (m_pApp != NULL)
  1348.     {
  1349.         CButton *pAppPropsBt = (CButton *)GetDlgItem(IDC_APPPROPERTY);
  1350.         if (pAppPropsBt != NULL)
  1351.             pAppPropsBt->EnableWindow(FALSE);
  1352.         Properties *pProps = NULL;
  1353.         HRESULT hRes = m_pApp->get_Properties(&pProps);
  1354.         if (SUCCEEDED(hRes))
  1355.         {
  1356.             CPropDialog dlgProp(pProps, this);
  1357.             if (dlgProp.DoModal() == IDOK)
  1358.             {
  1359.             }
  1360.             pProps->Release();
  1361.         }
  1362.         else
  1363.             AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1364.         if (pAppPropsBt != NULL)
  1365.             pAppPropsBt->EnableWindow(TRUE);
  1366.     }
  1367.     else
  1368.         AfxMessageBox(IDS_CREATEAPPFIRST);
  1369.     
  1370. }
  1371.  
  1372. void CLTSampleDlg::OnOptions() 
  1373. {
  1374.     CPropertySheet     sheet("Options", this);
  1375.     CSelOptPage    select;
  1376.  
  1377.     select.m_iVersion    = m_iVersion;
  1378.     select.m_bTopLevel    = m_wndView.m_varTopLevel.boolVal;
  1379.     select.m_bInvisible    = m_wndView.m_varInvisible.boolVal;
  1380.     select.m_bSegments    = m_wndView.m_varSegments.boolVal;
  1381.     select.m_bArcs        = m_wndView.m_varArcs.boolVal;
  1382.     select.m_bTexts        = m_wndView.m_varTexts.boolVal;
  1383.     select.m_bBlocks    = m_wndView.m_varBlocks.boolVal;
  1384.  
  1385.     sheet.AddPage(&select);
  1386.     if (sheet.DoModal() == IDOK)
  1387.     {
  1388.         m_wndView.m_varTopLevel.boolVal        = select.m_bTopLevel;
  1389.         m_wndView.m_varInvisible.boolVal    = select.m_bInvisible;
  1390.         m_wndView.m_varSegments.boolVal        = select.m_bSegments;
  1391.         m_wndView.m_varArcs.boolVal            = select.m_bArcs;
  1392.         m_wndView.m_varTexts.boolVal        = select.m_bTexts;
  1393.         m_wndView.m_varBlocks.boolVal        = select.m_bBlocks;
  1394.     }
  1395. }
  1396.  
  1397. void CLTSampleDlg::OnGetblock() 
  1398. {
  1399.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1400.     if (pDwgList != NULL)
  1401.     {
  1402.         int iSelItem = pDwgList->GetCurSel();
  1403.         if (iSelItem >= 0)
  1404.         {
  1405.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1406.             if (pIDwg != NULL)
  1407.             {
  1408.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  1409.                 pPropBt->EnableWindow(FALSE);
  1410.                 Selection *pSelection = NULL;
  1411.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1412.                 if (SUCCEEDED(hRes))
  1413.                 {
  1414.                     long lCount;
  1415.                     hRes = pSelection->get_Count(&lCount);
  1416.                     if (SUCCEEDED(hRes))
  1417.                     {
  1418.                         if (lCount = 1)
  1419.                         {
  1420.                             IGraphic *pIGr = NULL;
  1421.                             COleVariant varIndex((const long&)0);
  1422.  
  1423.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  1424.                             if (SUCCEEDED(hRes))
  1425.                             {
  1426.                                 Block *pBlock = NULL;
  1427.                                 hRes = pIGr->get_Block(&pBlock);
  1428.                                 if (SUCCEEDED(hRes))
  1429.                                 {
  1430.                                     pBlock->Release();
  1431.                                 }
  1432.                                 else
  1433.                                     AfxMessageBox(IDS_CANNOTGETBLOCK);
  1434.                                 pIGr->Release();
  1435.                             }
  1436.                             else
  1437.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1438.                         }
  1439.                         else
  1440.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1441.                     }
  1442.                     else
  1443.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1444.                     pSelection->Release();
  1445.                 }
  1446.                 else
  1447.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1448.                 pPropBt->EnableWindow(TRUE);
  1449.             }
  1450.             else
  1451.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1452.         }
  1453.     }
  1454. }
  1455.